//顶部导航
$(document).ready(function(){  
	//底部导航
	initPageFile();
	 setUser();
	 setChaptersList();
	 
});


var curChaptersID = "";//当前点击的章节
var curTheDraftID = ""; //草案编号
var curTheDraftTitle = "";//草案标题
//填充草案章节列表
function setChaptersList(){
	curTheDraftID = request.QueryString("id");//草案编号
	//获取数据库章节列表
	curTheDraftTitle = "企业名称登记管理实施办法（修订征求意见稿）";
	$("#main_title").html(curTheDraftTitle);
	$("#TheDraftTitle").html(curTheDraftTitle);
	//循环章节
	curChaptersID = "ch1";
	var chapt = "<li id='ch1' class='blue'  onmouseover='setonmouseoverClass(1)' onmouseout='setonmouseoutClass(1)'><a href='javascript:clickItem(1)'>第一章&nbsp; &nbsp;总则</a></li>"+
                "<li id='ch2' class='white' onmouseover='setonmouseoverClass(2)' onmouseout='setonmouseoutClass(2)'><a href='javascript:clickItem(2)'>第二章&nbsp;&nbsp; 企业名称 </a></li>"+
                "<li id='ch3' class='white' onmouseover='setonmouseoverClass(3)' onmouseout='setonmouseoutClass(3)'><a href='javascript:clickItem(3)'>第三章&nbsp;&nbsp; 企业名称的登记注册</a> </li>"+
                "<li id='ch4' class='white' onmouseover='setonmouseoverClass(4)' onmouseout='setonmouseoutClass(4)'><a href='javascript:clickItem(4)'>第四章&nbsp;&nbsp; 企业名称的使用 </a></li>"+
                "<li id='ch5' class='white' onmouseover='setonmouseoverClass(5)' onmouseout='setonmouseoutClass(5)'><a href='javascript:clickItem(5)'>第五章&nbsp;&nbsp; 监督管理与争议处理</a></li>"+
                "<li id='ch6' class='white' onmouseover='setonmouseoverClass(6)' onmouseout='setonmouseoutClass(6)'><a href='javascript:clickItem(6)'>第六章&nbsp;&nbsp; 附则</a></li>";

	$("#ChaptersList").html(chapt);
	clickItem(1);
}

function clickItem(id){
	//根据章节id获取小节列表
	document.getElementById(curChaptersID).className = "white";
	curChaptersID = "ch"+id;
	document.getElementById("ch"+id).className = "blue";
	$("#CommentsTitle").text(document.getElementById("ch"+id).innerText);
	var html = "";
	for(var i=1;i<10;i++){
		html += "<div class='canzj_lieb2_RightText'>第"+i+"条： 为了保护竞争和激励创新，制止经营者滥用知识产权排除、限制竞争的行为， 根据《中华人民共和国反垄断法》（以下简称《反垄断法》），制定本规定</div>"+
		"<div class='canzj_lieb2_button' style='width:760px;  margin-bottom:10px;'>"+
				"<div class='canzj_lieb2_dx' style='float:right; width:330px;'>"+
			          "<ul style='width:55px; float:right;'><li><a id='item_n_"+i+"' href='javascript:itemComments("+i+")'><font color='#1c8dd3'>查看意见</font></a></li></ul>"+
			          "<ul style='width:10px; float:right;'><li>|</li></ul>"+
			          "<ul style='width:65px; float:right;'><li>无意见</li><li><font color='#FF0000'>(5)</font></li></ul>"+
			          "<ul style='margin-right:10px; width:65px; float:right;'><li>不同意</li><li><font color='#FF0000'>(5)</font></li></ul>"+
			          "<ul style='float:right;'><li>修改</li><li><font color='#FF0000'>(5)</font></li></ul>"+
				"</div>"+
				"<div style='background:#cecece; height:1px; width:760px; clear:both;'></div>"+
		"</div>"+
		"<div style='height:50px; width:760px;'></div>";
	}
	
	$("#while_item_list").html(html);
	$(".login_foot").css("position","static");
	if($(document).height()<=$(window).height()){
		$(".login_foot").css("position","absolute");
		$(".login_foot").css("top",$(window).height()-66);
	}
}

//单条意见列表
function itemComments(id){
	var html = "grid";
	updateUserWindow = new Ext.Window({
		title : "草案条目意见列表",
		layout : 'fit',
		width :Ext.lib.Dom.getViewWidth()-50,
        height : Ext.lib.Dom.getViewHeight()-50,
		modal : true,
		closeAction :'hide',
		html:html,
		autoScroll:true,
		bodyStyle : 'background:#fff  repeat-y;'
	});
	updateUserWindow.show(Ext.get("item_n_"+id+""));
	
}


//全文下载
function downLoadWord(){
	//curTheDraftID 获取草案的word文件下载
}

//整体意见列表
var updateUserWindow = null;
function TheDraftComments(){
	var html = "grid";
	updateUserWindow = new Ext.Window({
		title : "草案整体意见列表",
		layout : 'fit',
		width :Ext.lib.Dom.getViewWidth()-50,
        height : Ext.lib.Dom.getViewHeight()-50,
		modal : true,
		closeAction :'hide',
		html:html,
		autoScroll:true,
		bodyStyle : 'background:#fff  repeat-y;'
	});
	updateUserWindow.show(Ext.get("zhengti"));
}

///////////////////////////////////////////////////////////////////////








function setonmouseoutClass(id){
	if("ch"+id==curChaptersID){
		document.getElementById("ch"+id).className = "blue";
	}else{
		document.getElementById("ch"+id).className = "white";
	}
}
function setonmouseoverClass(id){
	document.getElementById("ch"+id).className = "blue";
}


function setUser(){
	indexService.getUserBean(function(data){
		  UserBean = data;
		  if(UserBean.roleID=='5' || UserBean.roleID=='9'){//公众用户只能访问管理页面
			 // window.location = "caoanList.html";
		  }
		  if(UserBean.roleID!='5'){
			  $("#topuser").html("您好！"+UserBean.username+
				"<span style='width:10px; padding:0 10px;'>|</span><a href='LogoutServerServlet'>[退出]</a>");
		  }else{
			  $("#topuser").html("您还没有登录 <span style='width:10px; padding:0 10px;'>|</span><a href='"+UserBean.serverLogin+"'>[登录]</a>");
		  }
		  
	});
}

var request =
{
	QueryString : function(val)
	{
		var uri = window.location.search;
		var re = new RegExp("" +val+ "=([^&?]*)", "ig");
		return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
	}
};

function initPageFile(){
	//底部导航

	if($(document).height()<=$(window).height()){
        $(".login_foot").css("position","absolute");
        $(".login_foot").css("top",$(window).height()-66);
	  }
      $(window).resize(function(){   
           $(".login_foot").css("position","static");
		   if($(document).height()<=$(window).height()){
			$(".login_foot").css("position","absolute");
			$(".login_foot").css("top",$(window).height()-66);
	       }
      }); 
      
}
